package com.test;

import com.alibaba.fastjson.JSON;
import com.fasterxml.jackson.core.JsonParser;
import com.fasterxml.jackson.databind.ObjectMapper;

import java.io.IOException;
import java.util.Map;

/**
 * Created by Administrator on 2017/4/8.
 */
public class JsonDemo {

    public static void main(String[] args) throws IOException {
        String str = "{'cmd':'save','recid':1,'name':'form','record':{'recid':1,'fname':'Jane','lname':'Doe','email':'jdoe@gmail.com','sdate':'2017-04-15'}}";
        Map request = JSON.toJavaObject(JSON.parseObject(str), Map.class);
        System.out.println(request.get("record").getClass());

        System.out.println("*******************");
        ObjectMapper mapper = new ObjectMapper();
        // 处理 json中的“'”
        mapper.configure(JsonParser.Feature.ALLOW_SINGLE_QUOTES, true);
        // 标准 json要求k/v都是“"”，针对 k不是的情况特殊处理
        mapper.configure(JsonParser.Feature.ALLOW_UNQUOTED_FIELD_NAMES, true);
        Map request2 = mapper.readValue(str, Map.class);
        System.out.println(request2.get("record").getClass());

    }

}
